<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 500px;
            height: 500px;
            margin: 200px;
            border: 1px solid #000;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div></div>
    <script>
        // 1. 先获取鼠标点击时鼠标在页面中的距离( e.pageX  e.pageY )
        // 2. 其次得到盒子在页面的坐标（ .offsetLeft  .offsetTop）减去盒子在页面的距离， 得到鼠标在盒子内的坐标
        var div = document.querySelector('div');

        // div.addEventListener('mousemove', function(e) {
        div.addEventListener('click', function(e) {
            var x = e.pageX - this.offsetLeft;
            var y = e.pageY - this.offsetTop;
            this.innerHTML = 'x: '+ x + ' y: '+ y;
        })
    </script>
</body>
</html>